#include "filelist.h"
#include "ui_filelist.h"
#include <QListWidgetItem>
FileList::FileList(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::FileList)
{
    ui->setupUi(this);
    //允许扩展多选（点击拖拽范围 + Ctrl/Shift）
    ui->listWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
}

FileList::~FileList()
{
    delete ui;
}

void FileList::addItem(FileListItem* item)
{
    // 创建 QListWidgetItem 对象
    QListWidgetItem *listItem = new QListWidgetItem(ui->listWidget);

    // 设置 QListWidgetItem 的大小
    listItem->setSizeHint(item->sizeHint());
    ui->listWidget->addItem(listItem);
    ui->listWidget->setItemWidget(listItem,item);
}

void FileList::clear()
{
    ui->listWidget->clear();
}

void FileList::getSelectedItems(QList<QListWidgetItem *> *listItems)
{
    *listItems = ui->listWidget->selectedItems();
}

QListWidget *FileList::getListWidget()
{
    return ui->listWidget;
}


